import 'package:flutter/material.dart';
import 'package:kasax_demos2/entry/data_posts_test.dart';

/// SliverAppBar+SliverGrid+SliverFixedExtentList
class NewSliverDemo2Home extends StatefulWidget {
  const NewSliverDemo2Home({Key? key}) : super(key: key);

  @override
  _NewSliverDemo2HomeState createState() => _NewSliverDemo2HomeState();
}

class _NewSliverDemo2HomeState extends State<NewSliverDemo2Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          const SliverAppBar(
            expandedHeight: 250.0,
            flexibleSpace: FlexibleSpaceBar(
              title: Text("Coderwhy Demo"),
              background: Image(
                image: NetworkImage(
                    "https://tva1.sinaimg.cn/large/006y8mN6gy1g72j6nk1d4j30u00k0n0j.jpg"),
                fit: BoxFit.cover,
              ),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.all(8),
            sliver: SliverGrid(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2, crossAxisSpacing: 8, mainAxisSpacing: 8),
              delegate: SliverChildBuilderDelegate((context, index) {
                return Container(
                  alignment: Alignment(0, 0),
                  child: Image.network(
                    PostsDatas.TEST_POSTS[index].imageUrl,
                    fit: BoxFit.cover,
                  ),
                );
              }, childCount: PostsDatas.TEST_POSTS.length),
            ),
          )
        ],
      ),
    );
  }
}
